package com.ljq.software_springboot.softwareprogram.imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ljq.software_springboot.softwareprogram.entity.Account;
import com.ljq.software_springboot.softwareprogram.entity.Friendship;
import com.ljq.software_springboot.softwareprogram.mapper.AccountMapper;
import com.ljq.software_springboot.softwareprogram.mapper.FriendshipMapper;
import com.ljq.software_springboot.softwareprogram.service.IFriendshipService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-28
 */
@Service
public class FriendshipServiceImpl extends ServiceImpl<FriendshipMapper, Friendship> implements IFriendshipService {
    @Autowired
    FriendshipMapper friendshipMapper;
    @Autowired
    AccountMapper accountMapper;
    public List<Account> find(Integer id){
        LambdaQueryWrapper<Friendship> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Friendship::getUserId, id);
        List<Friendship> existing = friendshipMapper.selectList(queryWrapper);
        List<Account> accounts = new ArrayList<>();
        for (Friendship friendship : existing) {
            accounts.add(accountMapper.selectById(friendship.getFriendId()))
            ;
        }
        return accounts;
    }
}
